package cn.myfirefly.moming.integrate.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.myfirefly.moming.integrate.model.WorkCalendarDto;
import cn.myfirefly.moming.integrate.service.WorkCalendarService;
import cn.myfirefly.core.BaseController;
import cn.myfirefly.core.Const;
import cn.myfirefly.core.model.ResultDto;

@Controller
@RequestMapping("workcalendar")
public class WorkCalendarController extends BaseController {

	@Autowired
	WorkCalendarService workCalendarService;
	
	@RequestMapping("index.do")
	public String index(HttpServletRequest request, 
			HttpServletResponse response) {
		request.setAttribute("exceptionDate", workCalendarService.getWorkDates());
		return "work-calendar/index";
	}
	
	@RequestMapping("edit.do")
	public String edit(HttpServletRequest request, 
			HttpServletResponse response) {
		
		return "work-calendar/edit";
	}
	
	@RequestMapping("save.do")
	@ResponseBody
	public ResultDto save(WorkCalendarDto dto, HttpServletRequest request, 
			HttpServletResponse response) {
		warpModifyInfo(dto, request);
		String msg = workCalendarService.save(dto);
		if (!Const.ResultCode.SUCCESS.equals(msg)) {
			return error(msg);
		}
		return success("保存成功");
	}
	
	@RequestMapping("del.do")
	@ResponseBody
	public ResultDto del(WorkCalendarDto dto, HttpServletRequest request, 
			HttpServletResponse response) {
		String msg = workCalendarService.del(dto.getWorkCalendarSn());
		if (!Const.ResultCode.SUCCESS.equals(msg)) {
			return error(msg);
		}
		return success("删除成功");
	}
	
	@RequestMapping("getWorkDate.do")
	@ResponseBody
	public ResultDto getWorkDate(WorkCalendarDto dto, HttpServletRequest request, 
			HttpServletResponse response) {
		WorkCalendarDto retDto = workCalendarService.getWorkDate(dto.getDateValue());
		if (retDto == null) {
			retDto = new WorkCalendarDto();
			retDto.setDateValue(dto.getDateValue());
		}
		return success(retDto);
	}
}
